package main

import (
	"gin_v0dot2b/gin"
)

func main() {

	// 创建一个空的gin引擎
	r := gin.Default()
	m := make(map[string]string)
	m["a"] = "Hello"

	authorized := r.Group("/", gin.BasicAuth(gin.Accounts{
		"tom": "123",
		"tim": "456",
	}))
	{
		//authorized.Static("/src", "D:\\23魔方")

		authorized.GET("/hello", func(c *gin.Context) {
			c.String(200, "HelloWorld:%s", "xue")
		})
		authorized.POST("/admin", func(c *gin.Context) {
			// 断言
			//user := c.Get("user").(string)

			var json struct {
				Value string `json:"value" binding:"required"`
			}

			if c.Bind(&json) {
				c.JSON(200, gin.H{
					"value": json.Value,
				})
			}

		})
	}
	r.NotFound404(func(c *gin.Context) {
		c.Writer.Write([]byte("404"))
	})

	r.Run(":8080")

}

//func base64Test() {
//	bytes := []byte("hello world")
//	fmt.Println(bytes)
//	toString := base64.StdEncoding.EncodeToString([]byte("hello world"))
//	fmt.Println("base64编码:", toString)
//	decodeString, _ := base64.StdEncoding.DecodeString(toString)
//	fmt.Println("base64解码:", decodeString, string(decodeString))
//}

//type MySlice []int
//
//func (s MySlice) Len() int {
//	return len(s)
//}
//func (s MySlice) Less(i, j int) bool {
//	return s[i] < s[j]
//}
//func (s MySlice) Swap(i, j int) {
//	s[i], s[j] = s[j], s[i]
//}
//
//// sort 排序测试
//func sortTest() {
//	slice := MySlice{6, 2, 3, 4, 5}
//	sort.Sort(slice)
//	fmt.Println(slice)
//}

//func test() string {
//	for i := 1; ; i++ {
//		pc, file, line, ok := runtime.Caller(i)
//		if !ok {
//			break
//		}
//		fmt.Println(pc, file, line, ok)
//	}
//	fmt.Println("循环结束")
//	return "Hello"
//}
